package com.cjm.one.webmanager.controller.system;

import com.cjm.one.common.result.Result;
import com.cjm.one.model.system.entity.SysResource;
import com.cjm.one.model.system.vo.SysResourceVo;
import com.cjm.one.webmanager.service.system.SysMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "1-系统菜单管理" )
@RequestMapping("/manager/system/menu")
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;
    @PostMapping("/list")
    @Operation(summary = "查询菜单树状列表")
    public Result<List<SysResourceVo>> list(@RequestBody SysResource sysResource) {
        return Result.ok(sysMenuService.list(sysResource));
    }

    @PutMapping
    @Operation(summary = "修改菜单")
    public Result<Boolean> update(@RequestBody SysResource sysResource) {
        return Result.ok(sysMenuService.updateById(sysResource));
    }
    @PostMapping
    @Operation(summary = "添加菜单")
    public Result<Boolean> add(@RequestBody SysResource sysResource) {
        return Result.ok(sysMenuService.save(sysResource));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除菜单")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return Result.ok(sysMenuService.removeById(id));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据id获取菜单")
    public Result<SysResource> getById(@PathVariable("id") Long id){
        return Result.ok(sysMenuService.getById(id));
    }
}
